Skip to content

feat(Segment Membership): Seed identities on Beta opt-in#7899

Merged
khvn26 merged 19 commits into
mainfrom
feat/segment-membership-opt-in-seed
Jun 30, 2026
Merged

feat(Segment Membership): Seed identities on Beta opt-in#7899
khvn26 merged 19 commits into
mainfrom
feat/segment-membership-opt-in-seed

Conversation

@khvn26

@khvn26 khvn26 commented Jun 27, 2026

Copy link
Copy Markdown
Member

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #7471.
Closes #7911.

In this PR, we convert backfill_identities_to_clickhouse to a seed backfill expected to run once per org.

  • seed_organisation_identities(org_id) — on-demand one-shot seed for one org. Stamps inserted_at at scan start so a CDC write landing mid-scan wins ReplacingMergeTree dedup.
  • reconcile_segment_membership_seeds (hourly) — fires the seed once per allowed org, tracked by SegmentMembershipSeed model.
  • refresh_all_segment_counts every 6 hours.
  • Django admin action to force a re-seed (clears SegmentMembershipSeed for a given org).

All tasks that run the expensive ClickHouse queries are debounced.

We also bump SQL engine dep to incorporate the % Split fix.

Review complexity: 2/5.

How did you test this code?

Added new tests and modified existing where needed; will test extensively in staging.

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Jun 30, 2026 11:38am
flagsmith-frontend-preview Ready Ready Preview, Comment Jun 30, 2026 11:38am
flagsmith-frontend-staging Ready Ready Preview, Comment Jun 30, 2026 11:38am

Request Review

@github-actions github-actions Bot added api Issue related to the REST API feature New feature or request labels Jun 27, 2026
khvn26

This comment was marked as outdated.

khvn26 and others added 2 commits June 27, 2026 17:55
Run seed tests against live ClickHouse with a mocked Dynamo source,
inline the pending-task check, assert the whole skip event, use the
ClickHouseIdentityRow type, and replace the management command with a
Django admin re-seed action that clears the seed marker.

beep boop
Claude-Session: https://claude.ai/code/session_01EgZ5iHpDASZzCapiHRxHLB
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
Comment thread api/tests/unit/segment_membership/test_unit_segment_membership_admin.py Outdated
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
Comment thread api/tests/unit/segment_membership/test_unit_segment_membership_tasks.py Outdated
Comment thread api/tests/unit/segment_membership/test_unit_segment_membership_tasks.py Outdated
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
…t-in

Replace the daily all-org backfill with an on-demand
seed_organisation_identities(organisation_id) task and a lightweight
reconcile_segment_membership_seeds tick that fires it once per opted-in
org, tracked by a SegmentMembershipSeed marker. Seeded rows are versioned
at scan start so a CDC write landing mid-scan wins ReplacingMergeTree
dedup.

Keep a count-refresh safety-net as a separate recurring
refresh_all_segment_counts task (cadence via
SEGMENT_MEMBERSHIP_REFRESH_INTERVAL_HOURS, default 6) so cached counts
track CDC identity churn between segment edits. All refresh enqueues -
edit-triggered, seed fan-out, and the recurring sweep - route through
enqueue_membership_refresh, the single flag and debounce gate, so a
project never has duplicate refreshes queued.

Add a Django admin action to force a re-seed by clearing the marker.

beep boop
Claude-Session: https://claude.ai/code/session_01EgZ5iHpDASZzCapiHRxHLB
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 27, 2026
@github-actions github-actions Bot added feature New feature or request and removed docs Documentation updates labels Jun 30, 2026
…ith Exists

Filter `organisation` directly on `Project` and test live-segment existence
with a correlated `Exists`, instead of reaching the org through a segment
join and feeding ids into `IN`. Drop the server-side cursor: scoped to one
org this is a small set, and the heavy work is the per-project scan.

beep boop
Claude-Session: https://claude.ai/code/session_01EgZ5iHpDASZzCapiHRxHLB
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Jun 30, 2026
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Jun 30, 2026
@github-actions github-actions Bot added the docs Documentation updates label Jun 30, 2026
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request docs Documentation updates labels Jun 30, 2026
Pulls the percentage-split row-translation fix so segments split by
percentage report membership counts instead of showing empty.

beep boop
Claude-Session: https://claude.ai/code/session_01EgZ5iHpDASZzCapiHRxHLB
@github-actions github-actions Bot added the docs Documentation updates label Jun 30, 2026

@emyller emyller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segment membership: percentage-split segments always show zero members Retire backfill_identities_to_clickhouse task

2 participants